package club.weiyuanstudio.java.eedemo.mybatisdemo.service;

import club.weiyuanstudio.java.eedemo.mybatisdemo.dao.BookMapper;
import club.weiyuanstudio.java.eedemo.mybatisdemo.dao.model.Book;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Slf4j
@Service
public class BookService {
    private BookMapper bookMapper;

    @Autowired
    public void setBookMapper(BookMapper bookMapper) {
        this.bookMapper = bookMapper;
    }

    public List<Book> getAllBookService() {
        log.debug("Query All Book Name");
        return bookMapper.getAllBook();
    }

    public List<Book> getBookById(Long id) {
        log.debug("Get Book By Id");
        return bookMapper.getBookById(id);
    }

    public List<Book> getBookByName(String name) {
        log.debug("Query Book Name: " + name);
        return bookMapper.getBookByName("%" + name + "%");
    }

    public void addBook(String bookName, String author, Date publicationDate, Double price) {
        log.debug("Add Book: " + bookName);
        bookMapper.addBook(bookName, author, publicationDate, price);
    }

    public void deleteBookById(Long id) {
        bookMapper.deleteBookById(id);
    }
}
